package com.zd01.controller;

import com.zd01.model.BookModel;
import com.zd01.model.PageResult;
import com.zd01.model.SearchModel;
import com.zd01.model.StudentModel;
import com.zd01.servers.StudentServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentServer studentServer;

    @GetMapping
    public PageResult<StudentModel> getALl(SearchModel seachModel){
        log.info("分页查询 {}",seachModel);
        return studentServer.getALL(seachModel);

    }

    @PostMapping
    public void add(@RequestBody BookModel book){
        log.info("添加book {}",book);
        studentServer.add(book);

    }
    // 一对多，批量删除 del?ids=1,2,3,4
    @DeleteMapping("/dels")
    public void delete(@RequestParam List<Integer> ids){
        log.info("批量删除 {}", ids);
        studentServer.deletes(ids);
    }

    // 一对多，回显
    @GetMapping("/{id}")
    public BookModel getBookStudent(@PathVariable Integer id) {
        log.info("回显 {}", id);
        return studentServer.getBookStudent(id);
    }
    // 一对多，修改
    @PutMapping()
    public void update(@RequestBody BookModel book){
        log.info("修改 {}", book);
        studentServer.update(book);
    }
}
